//
//  UIImageView+WebImage.swift
//  weibo
//
//  Created by iobit on 2017/07/06.
//  Copyright © 2017 zhuxu. All rights reserved.
//

import SDWebImage


extension UIImageView {

    /// 隔离设置图像函数
    ///
    /// - Parameters:
    ///   - urlString: url
    ///   - placeholderImage: 占位图像
    func cz_setImage(urlString: String?, placeholderImage: UIImage?, isAvatar: Bool = false) {
        
        guard let urlString = urlString,
            let url = URL(string: urlString) else {
                image = placeholderImage
                return
        }
        // [weak self]避免循环引用
        sd_setImage(with: url, placeholderImage: placeholderImage, options: [], progress: nil) { [weak self] (image, _, _, _) in
            
            if isAvatar {
                self?.image = image?.cz_avaterImage(size: self?.bounds.size)
            }
        }
        
    }
    
}
